﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x020001AD RID: 429
	public class AimPoser : MonoBehaviour
	{
		// Token: 0x060008F8 RID: 2296 RVA: 0x00030EA8 File Offset: 0x0002F2A8
		public AimPoser.Pose GetPose(Vector3 localDirection)
		{
			if (this.poses.Length == 0)
			{
				return null;
			}
			for (int i = 0; i < this.poses.Length - 1; i++)
			{
				if (this.poses[i].IsInDirection(localDirection))
				{
					return this.poses[i];
				}
			}
			return this.poses[this.poses.Length - 1];
		}

		// Token: 0x060008F9 RID: 2297 RVA: 0x00030F0C File Offset: 0x0002F30C
		public void SetPoseActive(AimPoser.Pose pose)
		{
			for (int i = 0; i < this.poses.Length; i++)
			{
				this.poses[i].SetAngleBuffer((this.poses[i] != pose) ? 0f : this.angleBuffer);
			}
		}

		// Token: 0x040005A4 RID: 1444
		public float angleBuffer = 5f;

		// Token: 0x040005A5 RID: 1445
		public AimPoser.Pose[] poses = new AimPoser.Pose[0];

		// Token: 0x020001AE RID: 430
		[Serializable]
		public class Pose
		{
			// Token: 0x060008FB RID: 2299 RVA: 0x00030F84 File Offset: 0x0002F384
			public bool IsInDirection(Vector3 d)
			{
				if (this.direction == Vector3.zero)
				{
					return false;
				}
				if (this.yaw <= 0f || this.pitch <= 0f)
				{
					return false;
				}
				if (this.yaw < 180f)
				{
					Vector3 forward = new Vector3(this.direction.x, 0f, this.direction.z);
					if (forward == Vector3.zero)
					{
						forward = Vector3.forward;
					}
					Vector3 from = new Vector3(d.x, 0f, d.z);
					float num = Vector3.Angle(from, forward);
					if (num > this.yaw + this.angleBuffer)
					{
						return false;
					}
				}
				if (this.pitch >= 180f)
				{
					return true;
				}
				float num2 = Vector3.Angle(Vector3.up, this.direction);
				float num3 = Vector3.Angle(Vector3.up, d);
				return Mathf.Abs(num3 - num2) < this.pitch + this.angleBuffer;
			}

			// Token: 0x060008FC RID: 2300 RVA: 0x00031091 File Offset: 0x0002F491
			public void SetAngleBuffer(float value)
			{
				this.angleBuffer = value;
			}

			// Token: 0x040005A6 RID: 1446
			public bool visualize = true;

			// Token: 0x040005A7 RID: 1447
			public string name;

			// Token: 0x040005A8 RID: 1448
			public Vector3 direction;

			// Token: 0x040005A9 RID: 1449
			public float yaw = 75f;

			// Token: 0x040005AA RID: 1450
			public float pitch = 45f;

			// Token: 0x040005AB RID: 1451
			private float angleBuffer;
		}
	}
}
